package cn.openea.perpartner.crm.web.controller;



import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.common.core.web.page.TableDataInfo;
import cn.openea.perpartner.crm.web.entity.CrmUser;
import cn.openea.perpartner.crm.web.service.ICrmUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (CrmUser)表控制层
 *
 * @author Weird077
 * @since 2022-12-19 22:30:25
 */
@RestController
@RequestMapping("crmUser")
public class CrmUserController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ICrmUserService crmUserService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param crmUser 查询实体
     * @return 所有数据
     */
    @GetMapping
    public TableDataInfo selectAll() {
        startPage();
        List<CrmUser> list = this.crmUserService.list();
        return getDataTable(list);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public AjaxResult selectOne(@PathVariable Serializable id) {
        return success(this.crmUserService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param crmUser 实体对象
     * @return 新增结果
     */
    @PostMapping
    public AjaxResult insert(@RequestBody CrmUser crmUser) {
        return success(this.crmUserService.save(crmUser));
    }

    /**
     * 修改数据
     *
     * @param crmUser 实体对象
     * @return 修改结果
     */
    @PutMapping
    public AjaxResult update(@RequestBody CrmUser crmUser) {
        return success(this.crmUserService.updateById(crmUser));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
        return success(this.crmUserService.removeByIds(idList));
    }
}

